#include <func.h>
int main(int argc, char *argv[])
{
    // ./client 192.168.19.147 1234
    //ARGS_CHECK(argc, 3);
    // read client.conf
    FILE* fp = fopen("client.conf", "r");
    char ip[256];
    char port[256];
    char threadNum[256];

    fscanf(fp, "%s %s %s", ip, port, threadNum);
    fclose(fp);

    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_addr.s_addr = inet_addr(ip);
    serverAddr.sin_port = htons(atoi(port));
    connect(sockfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
    char buf1[4096]; // 客户端输入的所有字符
    char cmd[4096];        // 客户端输入的命令
    char cd[] = "cd"; char ls[] = "ls"; char pwd[] = "pwd"; char mkdir[] = "mkdir";
    char remove[] = "remove"; //char puts[] = "puts"; char gets[] = "gets";
    int flag_cd;
    int flag_ls;
    int flag_pwd;
    int flag_mkdir;
    int flag_remove;
    int flag_puts;
    int flag_gets;

    char username[256];
    //char password[256];
    // 假设username是zhang，password是123
    // 注册
    // 验证操作
    printf("welcome!\n");
    printf("1 : sign in, 2 : sign up\n");
    // 暂时只考虑注册, 默认客户第一次输入了2
    fd_set rdset; 
    while (1)
    {
        FD_ZERO(&rdset);
        FD_SET(STDIN_FILENO, &rdset);
        FD_SET(sockfd, &rdset); // 将stdin和sockfd放入监听队列
        select(sockfd + 1, &rdset, NULL, NULL, NULL);
        if (FD_ISSET(STDIN_FILENO, &rdset)) // 客户端stdin有输入了
        {
            // 目前只考虑注册
            read(STDIN_FILENO, buf1, sizeof(buf1));
            // 客户端输入的内容发送给服务端
            send(sockfd, buf1, sizeof(buf1), 0);

            //for (int i = 0; buf1[i] != ' '; i++)
            //{
                //cmd[i] = buf1[i];
            //}
            //flag_cd = strcmp(cmd, cd);
            //flag_ls = strcmp(cmd, ls);
            //flag_pwd = strcmp(cmd, pwd);
            //flag_mkdir = strcmp(cmd, mkdir);
            //flag_remove = strcmp(cmd, remove);
            //flag_puts = strcmp(cmd, puts);
            //flag_gets = strcmp(cmd, gets);

            /*if (flag_cd == 0) // 客户端输入的命令是cd
            { 
            }
            if (flag_ls == 0) // 客户端输入的命令是ls
            { 
            }
            if (flag_pwd == 0) // 客户端输入的命令是pwd
            { 
            }
            if (flag_mkdir == 0) // 客户端输入的命令是mkdir
            { 
            }
            if (flag_remove == 0) // 客户端输入的命令是remove
            { 
            }
            if (flag_puts == 0) // 客户端输入的命令是puts
            { 
            }
            if (flag_gets == 0) // 客户端输入的命令是gets
            {
            }*/
        }
        if (FD_ISSET(sockfd, &rdset)) // 服务端那边传输内容过来了
        {
        }
    }

    return 0;
}
